<?php
/*--------------------------------------------------------------------------------------------------
    customer_account_status_repair.php 2022-10-28
    Gambio GmbH
    http://www.gambio.de
    Copyright (c) 2022 Gambio GmbH
    Released under the GNU General Public License (Version 2)
    [http://www.gnu.org/licenses/gpl-2.0.html]
    --------------------------------------------------------------------------------------------------
 */

/** @var DatabaseModel $this */
/** @var int $t_success */

$sql    = "SELECT COALESCE(`value`, `default`) as `value` FROM `gx_configurations` WHERE `key` = 'configuration/DEFAULT_CUSTOMERS_STATUS_ID_GUEST'";
$result = $this->query($sql, true);

$guestCustomerStatusId = 1;

if ($result->num_rows > 0) {
    $row                   = $result->fetch_assoc();
    $guestCustomerStatusId = (int)$row['value'];
}

$update = "UPDATE `customers` SET `account_type` = 1 WHERE `customers_status` = {$guestCustomerStatusId};";
$t_success &= $this->query($update, true);
